#!/bin/sh
if [ x$1 = x ]; then
    nodes=1
else
    nodes=$1
    nn=$2
fi
printf "node $nn of $nodes\n"
printf "ulimit = %s\n" `ulimit -n`
PATH=/opt/local/bin:$PATH
APP=../dpipe
LOGBASE="./log"
D=0.5
T=20
P=10
V="-v"
W=4
pids=""
NW=$(( $W / $nodes ))
#
for (( i=0 ; i < $NW ; ++i )) do
    $APP w -v -v --tx --stages=2 --procs=$P --delay=$D $V 2>$LOGBASE.worker.node$nn.$i &
    pids="$pids $!"
done
if [ $nn -eq 1 ]; then
    sleep 2
    $APP c $V -v --stages=2 --tasks=$T --workers=$W --procs=$P --file=c.out 2>$LOGBASE.consumer &
    pids="$pids $!"
    sleep 2
    $APP p -v -v --tasks=$T --workers=$W --procs=$P $V 2>$LOGBASE.master &
fi
#
echo "Logs in $LOGBASE.(workerN,consumer,master)"
pids="$pids $!"
echo "Started PIDS: $pids"

